<div class="hbox hbox-auto-xs hbox-auto-sm" ng-init="
    app.settings.asideFolded = false;
    app.settings.asideDock = false;
  ">
    <!-- main -->
    <div class="col">
        <!-- main header -->
        <div class="bg-light lter b-b wrapper-md">
            <div class="row">
                <div class="col-sm-6 col-xs-12">
                    <h1 class="m-n font-thin h3 text-black">阿里云RAM用户管理</h1>
                    <small class="text-muted">用户管理</small>
                </div>
            </div>
        </div>
        <!-- / main header -->
        <div class="wrapper-md">
            <!-- toaster directive -->
            <toaster-container
                    toaster-options="{'position-class': 'toast-top-right', 'close-button':true}"></toaster-container>
            <!-- / toaster directive -->

            <div class="panel panel-default" ng-controller="aliyunRamUserCtrl">
                <div class="panel-body">

                    <form class="form-inline" role="form">
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon">RAM用户名</span>
                                <input type="text" class="form-control" ng-model="queryUsername" placeholder="RAM用户名">
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon">用户标签</span>
                                <input type="text" class="form-control" ng-model="queryUserTag" placeholder="RAM用户标签">
                            </div>
                            <div class="form-group">
                                <div class="input-group">
                                    <span class="input-group-addon">AccessKey</span>
                                    <select class="form-control" ng-model="nowKeyType"
                                            ng-options="keyType.code as keyType.name for keyType in keyTypes">
                                        <option value="">--请选择--</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <button type="button" class="btn btn-info" ng-click="queryUser()"><span
                                    class="glyphicon glyphicon-search"></span>搜索
                            </button>
                            <button type="button" class="btn btn-info" ng-click="reSet()"><span
                                    class="glyphicon glyphicon-repeat"></span>重置
                            </button>
                            <button type="button" class="btn btn-success" ng-click="updateUsers()">
                                <i class="fa fa-spin fa-spinner" ng-show="butUpdateUsers"></i>
                                <i class="glyphicon glyphicon-repeat" ng-show="!butUpdateUsers"></i>同步阿里云用户
                            </button>
                        </div>
                    </form>

                    <div class="panel panel-default" style="margin-top: 5px;;">
                        <div class="panel-body">
                            <div>
                                <table class="table table-hover table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <td class="col-md-2">RAM用户详情</td>
                                        <td class="col-md-2">本地用户</td>
                                        <td class="col-md-3">策略名称</td>
                                        <td class="col-md-2">AccessKey</td>
                                        <td>创建时间</td>
                                        <td>操作</td>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr ng-repeat="item in pageData">
                                        <td>
                                            <span style="background-color: #2b669a; color: white;"
                                                  uib-popover-html="item.comments" popover-trigger="'mouseenter'"
                                                  class="label">{{item.ramUserName}}</span>
                                            <span ng-show="item.ramDisplayName != ''">
                                                </br>
                                                <b style="color: #2b669a"
                                                   uib-popover-html="'显示名称'" popover-trigger="'mouseenter'">{{item.ramDisplayName}}</b>
                                                 <span style="color: #777"
                                                       uib-popover-html="'用户标签'" popover-trigger="'mouseenter'"
                                                       class="pull-right">{{item.userTag}}</span>
                                            </span>
                                            </br>
                                            <span class="fa fa-key" uib-popover-html="'AccessKey数量'"
                                                  popover-trigger="'mouseenter'"></span>
                                            <i class="badge bg-success"
                                               ng-if="item.accessKeys > 0">{{item.accessKeys}}</i>
                                            <i class="badge" style="background-color: #777"
                                               ng-if="item.accessKeys == 0">{{item.accessKeys}}</i>
                                            </br>
                                        </td>
                                        <td>
                                            <span style="background-color: #2b669a; color: white;"
                                                  class="label">{{item.userVO.username}}</span>
                                            <span ng-show="item.userVO.displayName != ''">
                                                </br>
                                                <b style="color: #2b669a"
                                                   uib-popover-html="'名称'" popover-trigger="'mouseenter'">{{item.userVO.displayName}}</b>
                                            </span>
                                            <span ng-show="item.userVO.mail != ''">
                                                </br>
                                                <b style="color: #777"
                                                   uib-popover-html="'邮箱'" popover-trigger="'mouseenter'">{{item.userVO.mail}}</b>
                                            </span>
                                        </td>
                                        <td>
                                            <div class="col-md-12" style="margin-top:5px;"
                                                 ng-repeat="policy in item.policyList">
                                               <span style="background-color: #777; color: white;"
                                                     uib-popover-html="policy.description"
                                                     popover-trigger="'mouseenter'"
                                                     class="label">{{policy.policyName}}</span>
                                                <span class="label" style="background-color: #ff5f87; color: white;"
                                                      ng-show="policy.policyType == 'Custom'">自定义</span>
                                                <span class="label" style="background-color: #20a03f; color: white;"
                                                      ng-show="policy.policyType == 'System'">系统</span>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="col-md-12" style="margin-top:5px;"
                                                 ng-repeat="accessKey in item.accessKeyList">
                                               <span style="background-color: #777; color: white;"
                                                     uib-popover-html="policy.description"
                                                     popover-trigger="'mouseenter'"
                                                     class="label">{{accessKey.accessKeyId}}</span>
                                            </div>

                                        </td>
                                        <td>
                                            {{(item.gmtModify == null || item.gmtModify == '') ? item.gmtCreate : item.gmtModify}}
                                        </td>
                                        <td>
                                            <button ng-click="editRamUserInfo(item)"
                                                    class="btn btn-xs"
                                                    style="background-color: #2b669a; color: white;">
                                                <span class="glyphicon glyphicon-edit"></span>编辑标签
                                            </button>

                                            <button ng-click="importPolicy(item.id)"
                                                    ng-show="item.userVO != null && item.policyList.length != 0 && item.userVO.username != item.ramUserName"
                                                    class="btn btn-xs"
                                                    style="background-color: #c9302c; color: white;">
                                                <span class="fa fa-spin fa-spinner" ng-show="butImportPolicy"></span>
                                                <span class="icon icon-cursor" ng-show="!butImportPolicy"></span>导入策略
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td colspan="9">
                                            <ul style="margin: 0px; float: right;" uib-pagination
                                                total-items="totalItems" ng-model="currentPage"
                                                items-per-page="pageLength" max-size="10"
                                                ng-change="pageChanged()" previous-text="&lsaquo;"
                                                next-text="&rsaquo;"></ul>
                                        </td>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>
    <!-- / main -->
</div>


<script type="text/ng-template" id="editRamUserInfo">
    <div ng-include="'tpl/modal/aliyun/edit_ram_user_info_modal.html'"></div>
</script>
